package com.rizzo.android.ui;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class BootstrapActivity extends Activity {

    private static final int NEW_ACCOUNT = 0;
    private static final int EXISTING_ACCOUNT = 1;
    private AccountManager accountManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//		setContentView(R.layout.bootstrap);
        this.accountManager = AccountManager.get(this);
        Account[] accounts = this.accountManager.getAccountsByType(AuthenticatorActivity.PARAM_ACCOUNT_TYPE);
        if (accounts.length == 0) {
            final Intent i = new Intent(this, AuthenticatorActivity.class);
            i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
            startActivityForResult(i, NEW_ACCOUNT);
        } else {
            String password = this.accountManager.getPassword(accounts[0]);
            if (password == null) {
                final Intent i = new Intent(this, AuthenticatorActivity.class);
//				i.putExtra(AuthenticatorActivity.PARAM_USER, accounts[0].name);
                startActivityForResult(i, EXISTING_ACCOUNT);
            } else {
                startActivity(new Intent(this, MainPagerActivity.class));
                finish();
            }
        }

    }
}